﻿using System.IO;
using Expect.Core.IO;
using Microsoft.CSharp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Expect.Core.CodeGen;
using Expect.Core.Test.IO;

namespace Expect.Core.Test.VisualStudio
{    
    [TestClass]
    public class CodeGen
    {
        [TestMethod]
        public void CodeGen_Can_Parse_Text_Spec()
        {
            string fname = "ComplexSpec.txt";
            string specText = Helper.LoadFromRessourceFile(fname);
            var result = new TextSpecificationReader().ReadSpecification(fname, specText);
            GenerationInfo nfo = new GenerationInfo();
            nfo.Provider = new CSharpCodeProvider();
            nfo.CodeFileNameSpace = "MyNamespace";
            nfo.CodeFilePath = "my folder\\myfile.expect";
            nfo.CodeFileName = "myfile";
            nfo.Config = new CodeGenConfig();
            nfo.ProjectFolder = "my folder";

            ExpectTestGenerator generator = new ExpectTestGenerator(nfo, result);
            string classcontent = generator.Execute();
            using (StreamWriter writer = new StreamWriter("e:\\temp\\myclass.cs"))
            {
                writer.Write(classcontent);
            }
        }

        [TestMethod]
        public void CodeGen_Can_Parse_SampleText_Spec()
        {
            string fname = "SampleTextSpec.txt";
            string specText = Helper.LoadFromRessourceFile(fname);
            var result = new TextSpecificationReader().ReadSpecification(fname, specText);
            GenerationInfo nfo = new GenerationInfo();
            nfo.Provider = new CSharpCodeProvider();
            nfo.CodeFileNameSpace = "MyNamespace";
            nfo.CodeFilePath = "my simple folder\\mysimplefile.expect";
            nfo.CodeFileName = "mysimplefile";
            nfo.Config = new CodeGenConfig();
            nfo.ProjectFolder = "my simple folder";

            ExpectTestGenerator generator = new ExpectTestGenerator(nfo, result);
            string classcontent = generator.Execute();
            using (StreamWriter writer = new StreamWriter("e:\\temp\\simpleclass.cs"))
            {
                writer.Write(classcontent);
            }
        }

        [TestMethod]
        public void CodeGen_Can_Parse_Report_Metadata()
        {
            string fname = "reportmetadata.txt";
            string content = Helper.LoadFromRessourceFile(fname);
            DummyReportData data = new DummyReportData();
            
            GenerationInfo nfo = new GenerationInfo();
            nfo.Provider = new CSharpCodeProvider();
            nfo.CodeFileNameSpace = "MyNamespace";
            nfo.CodeFilePath = "myfile.expect";
            nfo.CodeFileName = "myfile";
            nfo.Config = new CodeGenConfig();
            nfo.ProjectFolder = "my folder";

            string classcontent = ReportMetadataGenerator.Execute(nfo, fname, content);

            using (StreamWriter writer = new StreamWriter("e:\\temp\\myreportclass.cs"))
            {
                writer.Write(classcontent);
            }
        }
    }
}
